/*
* pps_bom
*/
package com.pitop.mould.service;

import com.pitop.core.entity.Page;
import com.pitop.core.exceptions.BaseException;
import com.pitop.core.exceptions.MouldMaterialException;
import com.pitop.mould.api.MouldMaterialFeignApi;
import com.pitop.mould.entity.MouldMaterial;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 物料模具关联
 *
 * @author berton
 */
@Service("mouldMaterialSVImpl")
@Slf4j
public class MouldMaterialSVImpl {

    @Autowired
    private MouldMaterialFeignApi mouldMaterialFeignApi;

    /**
     * 加载一个对象MouldMaterial
     *
     * @param id * @param materialCode 物料编码* @param mouldCode 模具编码
     * @return MouldMaterial
     */
    public MouldMaterial load(Long id, String materialCode, String mouldCode) {
        if (id == null && materialCode == null && mouldCode == null) {
            throw new MouldMaterialException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return mouldMaterialFeignApi.load(id, materialCode, mouldCode);
    }

    /**
     * 加载一个对象MouldMaterial 通过id,(将查询关联数据)
     *
     * @param id
     * @return MouldMaterial
     */
    public MouldMaterial loadById(Long id) {
        if (id == null) {
            throw new MouldMaterialException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return mouldMaterialFeignApi.loadById(id);
    }

    /**
     * 加载一个对象MouldMaterial 通过materialCode,(将查询关联数据)
     *
     * @param materialCode 物料编码
     * @return MouldMaterial
     */
    public MouldMaterial loadByMaterialCode(String materialCode) {
        if (materialCode == null) {
            throw new MouldMaterialException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return mouldMaterialFeignApi.loadByMaterialCode(materialCode);
    }

    /**
     * 加载一个对象MouldMaterial 通过mouldCode,(将查询关联数据)
     *
     * @param mouldCode 模具编码
     * @return MouldMaterial
     */
    public MouldMaterial loadByMouldCode(String mouldCode) {
        if (mouldCode == null) {
            throw new MouldMaterialException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return mouldMaterialFeignApi.loadByMouldCode(mouldCode);
    }

    /**
     * 加载一个对象MouldMaterial,(将查询关联数据)
     *
     * @param id * @param materialCode 物料编码* @param mouldCode 模具编码
     * @return MouldMaterial
     */
    public MouldMaterial get(Long id, String materialCode, String mouldCode) {
        if (id == null && materialCode == null && mouldCode == null) {
            throw new MouldMaterialException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return mouldMaterialFeignApi.get(id, materialCode, mouldCode);
    }

    /**
     * 加载一个对象MouldMaterial 通过id,(将查询关联数据)
     *
     * @param id
     * @return MouldMaterial
     */
    public MouldMaterial getById(Long id) {
        if (id == null) {
            throw new MouldMaterialException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return mouldMaterialFeignApi.getById(id);
    }

    /**
     * 加载一个对象MouldMaterial 通过materialCode,(将查询关联数据)
     *
     * @param materialCode 物料编码
     * @return MouldMaterial
     */
    public MouldMaterial getByMaterialCode(String materialCode) {
        if (materialCode == null) {
            throw new MouldMaterialException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return mouldMaterialFeignApi.getByMaterialCode(materialCode);
    }

    /**
     * 加载一个对象MouldMaterial 通过mouldCode,(将查询关联数据)
     *
     * @param mouldCode 模具编码
     * @return MouldMaterial
     */
    public MouldMaterial getByMouldCode(String mouldCode) {
        if (mouldCode == null) {
            throw new MouldMaterialException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return mouldMaterialFeignApi.getByMouldCode(mouldCode);
    }

    /**
     * 删除对象MouldMaterial
     *
     * @param id * @param materialCode 物料编码* @param mouldCode 模具编码
     */

    public void delete(Long id, String materialCode, String mouldCode) {
        if (id == null && materialCode == null && mouldCode == null) {
            throw new MouldMaterialException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        mouldMaterialFeignApi.delete(id, materialCode, mouldCode);
    }

    /**
     * 查询MouldMaterial分页
     *
     * @param mouldMaterial 对象
     * @param curPage       当前页
     * @param pageSize      分页条数
     * @return List<MouldMaterial>
     */
    public List<MouldMaterial> list(MouldMaterial mouldMaterial, int curPage, int pageSize) {
        return mouldMaterialFeignApi.list(mouldMaterial, curPage, pageSize);
    }

    /**
     * 查询MouldMaterial分页
     *
     * @param id       * @param materialCode  物料编码* @param mouldCode  模具编码
     * @param curPage  当前页
     * @param pageSize 分页条数
     * @return List<MouldMaterial>
     */
    public List<MouldMaterial> list(Long id, String materialCode, String mouldCode, int curPage, int pageSize) {
        if (curPage < 0) {
            curPage = 1;
        }

        if (pageSize < 0) {
            pageSize = Page.limit;
        }

        MouldMaterial mouldMaterial = new MouldMaterial();
        mouldMaterial.setId(id);
        mouldMaterial.setMaterialCode(materialCode);
        mouldMaterial.setMouldCode(mouldCode);

        return mouldMaterialFeignApi.list(mouldMaterial, curPage, pageSize);
    }

    public int count(Long id, String materialCode, String mouldCode) {
        return mouldMaterialFeignApi.count(id, materialCode, mouldCode);
    }

    public int count(MouldMaterial mouldMaterial) {
        return mouldMaterialFeignApi.count(mouldMaterial);
    }

    /**
     * 保存
     *
     * @param mouldMaterial 实体
     * @throws BaseException
     */
    public void save(MouldMaterial mouldMaterial) {
        if (mouldMaterial == null) {
            throw new MouldMaterialException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        mouldMaterialFeignApi.build(mouldMaterial);
    }

    /**
     * 更新
     *
     * @param mouldMaterial 实体
     * @throws BaseException
     */
    public void modify(MouldMaterial mouldMaterial) {
        if (mouldMaterial == null) {
            throw new MouldMaterialException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        mouldMaterialFeignApi.modify(mouldMaterial);
    }
}
